-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REF: Remove side-effects from importing Styler #52995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
What about pushing the loading of templates into the render methods themselves. The class level parameters could just be strings defining the default template file location? Maybe keep the cached env loader. Currently we have def _render_html(...) -> str:
d = self._render(sparse_index, sparse_columns, max_rows, max_cols, " ")
d.update(kwargs)
return self.template_html.render(
**d,
html_table_tpl=self.template_html_table,
html_style_tpl=self.template_html_style,
) then perhaps .. class StyleRender:
template_html = "some_string_path"
...
def _render_html(...) -> str:
d = self._render(sparse_index, sparse_columns, max_rows, max_cols, " ")
d.update(kwargs)
template_html = self.env.get_template(self.template_html)
template_html_table = self.env.get_template(self.template_html_table)
template_html_style = self.env.get_template(self.template_html_style)
return template_html.render(
**d,
html_table_tpl=template_html_table,
html_style_tpl=template_html_style,
) |
@attack68: finally had some time to look into this. Your suggestion would make it so that users can no longer modify the templates. Is that a breaking change? |
Creating modified templates is documented as: class MyStyler(Styler):
env = Environment(
loader=ChoiceLoader([
FileSystemLoader("templates"), # contains ours
Styler.loader, # the default
])
)
template_html_table = env.get_template("myhtml.tpl") where It is my understanding that the native template files stored in the python environment are not really modifiable or suitable to be modified, but a user has to add custom templates which might refer to them, as is the case in the documentation. Im sure it is possible to create a more user friendly way of doing this which can still avoid your caching. |
Are you interested in taking this up? |
consider #53429 |
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.I initially pursued this because I thought it was necessary for #27522, but realize now Styler isn't defined in core. However it would be necessary for #52994 if we decide to go that route.
The "cached classmethods" are a bit of a hack. It works because when you set e.g.
StylerRenderer.template_string = some_value
, you're just overwriting the entire property with the value. Still looking for a better way to do this.